package com.woniu.carrent.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.carrent.pojo.TCar;
import com.woniu.carrent.pojo.vo.TCarTypecVo;
import com.woniu.carrent.pojo.vo.TCarVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TCarMapper extends BaseMapper<TCar> {
    @Select("SELECT c.`carId`,c.`carName`,cy.`cTypeName`\n" +
            "AS ctypename,b.`brandName`\n" +
            "AS brandname,c.`plate`,c.`pictures`,c.`price`,c.`isOnline`,c.`isDeleted`,c.`files`,l.`lName` \n" +
            "AS lname , c.`status`\n" +
            "FROM t_car c\n" +
            "JOIN t_carbrand b ON c.`brandId` = b.`brandId`\n" +
            "JOIN t_cartype cy ON c.`cTypeId` = cy.`cTypeId`\n" +
            "JOIN t_location l ON c.`lId` = l.`lId`" +
            "${ew.customSqlSegment}\n")
    List<TCar> queryCar(IPage<TCar> page,@Param("ew") QueryWrapper<TCar> wrapper);
    @Select("SELECT c.`carId` AS carid,c.`carName` AS carname\n" +
            "FROM t_car c\n" +
            "JOIN t_user seller ON seller.`lId` = c.lId\n" +
            "WHERE seller.`userId` = #{sellerId}")
    List<TCarTypecVo> selectCarBySellerId(Integer sellerId);
    // 添加根据品牌名称查询的方法
    @Select("SELECT * FROM t_car c " +
            "JOIN t_carbrand b ON c.brandId = b.brandId " +
            "WHERE b.brandName LIKE CONCAT('%', #{brandName}, '%') " +
            "AND c.isOnline = 1 AND c.isDeleted = 0")
    List<TCar> selectCarsByBrandName(String brandName);
}
